package com.errol.batchprocessor.batchprocessor.advisorimpl.batchsplitter;

import com.renjia.entity.AbstractImportBatch;
import com.renjia.service.generic.middleware.batchprocessor.payload.AbstractBatchPayload;
import com.renjia.service.generic.middleware.batchprocessor.payload.AbstractPiecePayload;
import com.renjia.service.generic.middleware.batchprocessor.payload.AbstractSinglePayload;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 分片算法需要的对象封装方法，由扩展点实现者来实现
 *
 * @author zhang xiao bin
 * @version v1.0
 * @date 2021/03/07
 * @since v5.0.5
 **/
public interface BatchSplitterHelper<IE extends AbstractImportBatch, AT extends Enum<?>, BE, SE, BP extends AbstractBatchPayload<IE, AT, BE, SE>, PP extends AbstractPiecePayload<SE, SP>, SP extends AbstractSinglePayload<SE>> {

    /**
     * 封装 PiecePayload 分片数据的模板方法
     *
     * @param singleEntityList SE 列表
     * @return PP
     */
    default PP newPiecePayload(List<SE> singleEntityList) {
        return packPiecePayload(singleEntityList.stream().map(this::packSinglePayload).collect(Collectors.toList()));
    }

    /**
     * 封装 PiecePayload 分片数据
     *
     * @param singlePayloadList SP 列表
     * @return PP
     */
    PP packPiecePayload(List<SP> singlePayloadList);

    /**
     * 封装 SinglePayload 单条数据载体
     *
     * @param singleEntity SE
     * @return SP
     */
    SP packSinglePayload(SE singleEntity);
}
